#include "StompedReality/Core/TypeSystem/TypeSystem.h"
#include "StompedReality/Math/Rectangle.h"

CreateRegDummy( Rectangle )

namespace StompedReality
{
namespace Math
{
Rectangle::Rectangle ( )
{
  this->m_Center = Vector2 ( 0, 0 );
  this->m_Center = Vector2 ( 0, 0 );
}

Rectangle::Rectangle ( StompedReality::Math::Vector2 center, StompedReality::Math::Vector2 halfsize )
{
  this->Initialize ( center, halfsize );
}

Rectangle::Rectangle ( float x, float y, float w, float h )
{
  this->Initialize ( StompedReality::Math::Vector2 ( x, y ), StompedReality::Math::Vector2 ( w, h ) );
}

Rectangle::~Rectangle( )
{
}

void Rectangle::Initialize ( StompedReality::Math::Vector2 center, StompedReality::Math::Vector2 halfsize )
{
  this->m_Center = center;
  this->m_HalfSize = halfsize;
}

bool Rectangle::Contains ( StompedReality::Math::Rectangle* other )
{
  return ( this->Left( ) < other->Left( ) && this->Top( ) < other->Top( ) &&
           this->Right( ) > other->Right( ) && this->Bottom( ) > other->Bottom( ) );
}

bool Rectangle::Contains ( StompedReality::Math::Vector2* point )
{
  return ( this->Left( ) < point->GetX( ) && this->Top( ) < point->GetY( ) &&
           this->Right( ) > point->GetX( ) && this->Bottom( ) > point->GetY( ) );
}

bool Rectangle::Instersects ( StompedReality::Math::Rectangle* other )
{
  return ( this->Left( ) < other->Right( ) && this->Right( ) > other->Left( ) &&
           this->Top( ) < other->Bottom( ) && this->Bottom( ) > other->Top( ) );
}

bool Rectangle::Contains ( StompedReality::Math::Vector2 pos, StompedReality::Math::Vector2 size,
                           StompedReality::Math::Vector2 point )
{
  return pos.GetX( ) < point.GetX( ) && pos.GetY( ) < point.GetY( ) &&
         (pos + size).GetX( ) > point.GetX( ) && (pos + size).GetY( ) > point.GetY( );
}

int StompedReality::Math::RectangleReg::registeType( )
{
  return ( int ) ( StompedReality::type_system::TypeSystem::CreateTypeInfo<Rectangle> ( "Rectangle" )->
                   addTypeField ( StompedReality::type_system::TypeField ( "center", &Rectangle::m_Center ) )->
                   addTypeField ( StompedReality::type_system::TypeField ( "half size", &Rectangle::m_HalfSize ) ) );
}

static int typeReg = StompedReality::Math::RectangleReg::registeType( );

}
}
